<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">厂别/车间</label>
        <el-input v-model="query.plant" clearable placeholder="厂别/车间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">车间描述</label>
        <el-input v-model="query.plantName" clearable placeholder="车间描述" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">需求单号</label>
        <el-input v-model="query.docNo" clearable placeholder="需求单号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">Auto自动 / Manual手动</label>
        <el-input v-model="query.callType" clearable placeholder="Auto自动 / Manual手动" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">DCS叫料 / MES叫料</label>
        <el-input v-model="query.callSystem" clearable placeholder="DCS叫料 / MES叫料" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">单据类型：Picking、Dispatch、OVER</label>
        <el-input v-model="query.docType" clearable placeholder="单据类型：Picking、Dispatch、OVER" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="厂别/车间" prop="plant">
            <el-input v-model="form.plant" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="车间描述" prop="plantName">
            <el-input v-model="form.plantName" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="需求单号" prop="docNo">
            <el-input v-model="form.docNo" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="Auto自动 / Manual手动" prop="callType">
            <el-input v-model="form.callType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="DCS叫料 / MES叫料" prop="callSystem">
            <el-input v-model="form.callSystem" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="单据类型：Picking、Dispatch、OVER" prop="docType">
            <el-input v-model="form.docType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="需求区域" prop="demandArea">
            <el-input v-model="form.demandArea" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="申请人" prop="applicant">
            <el-input v-model="form.applicant" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="合并单号">
            <el-input v-model="form.mergeNo" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="合并套数">
            <el-input v-model="form.mergeSets" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="描述">
            <el-input v-model="form.commentText" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="交易类型：261、311">
            <el-input v-model="form.mvt" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="首发1 / 续发2">
            <el-input v-model="form.transactionType" style="width: 250px;" />
          </el-form-item>
          <!-- <el-form-item label="创建时间" prop="createTime">
            <el-input v-model="form.createTime" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="更新时间" prop="updateTime">
            <el-input v-model="form.updateTime" style="width: 250px;" />
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <!-- <el-table-column prop="id" label="自增主键" /> -->
        <el-table-column prop="plant" label="厂别/车间" />
        <el-table-column prop="plantName" label="车间描述" />
        <el-table-column prop="docNo" label="需求单号" />
        <el-table-column prop="callType" label="Auto自动 / Manual手动" />
        <el-table-column prop="callSystem" label="DCS叫料 / MES叫料" />
        <el-table-column prop="docType" label="单据类型：Picking、Dispatch、OVER" />
        <el-table-column prop="demandArea" label="需求区域" />
        <el-table-column prop="applicant" label="申请人" />
        <el-table-column prop="mergeNo" label="合并单号" />
        <el-table-column prop="mergeSets" label="合并套数" />
        <el-table-column prop="commentText" label="描述" />
        <el-table-column prop="mvt" label="交易类型：261、311" />
        <el-table-column prop="transactionType" label="首发1 / 续发2" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','dcsOrderDemandHeader:edit','dcsOrderDemandHeader:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="checkDetail(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDcsOrderDemandHeader from '@/api/work/dcsOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { plant: null, plantName: null, docNo: null, callType: null, callSystem: null, docType: null, demandArea: null, applicant: null, mergeNo: null, mergeSets: null, commentText: null, mvt: null, transactionType: null }
export default {
  name: 'DcsOrder',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'dcs_order_demand_header', url: 'api/dcsOrderDemandHeader', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDcsOrderDemandHeader },
      optShow: {
        add: true,
        edit: true,
        download: true,
        reset: true,
        del: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dcsOrderDemandHeader:add'],
        edit: ['admin', 'dcsOrderDemandHeader:edit'],
        del: ['admin', 'dcsOrderDemandHeader:del']
      },
      rules: {
        // plant: [
        //   { required: true, message: '厂别/车间不能为空', trigger: 'blur' }
        // ],
        // plantName: [
        //   { required: true, message: '车间描述不能为空', trigger: 'blur' }
        // ],
        // docNo: [
        //   { required: true, message: '需求单号不能为空', trigger: 'blur' }
        // ],
        // callType: [
        //   { required: true, message: 'Auto自动 / Manual手动不能为空', trigger: 'blur' }
        // ],
        // callSystem: [
        //   { required: true, message: 'DCS叫料 / MES叫料不能为空', trigger: 'blur' }
        // ],
        // docType: [
        //   { required: true, message: '单据类型：Picking、Dispatch、OVER不能为空', trigger: 'blur' }
        // ],
        // demandArea: [
        //   { required: true, message: '需求区域不能为空', trigger: 'blur' }
        // ],
        // applicant: [
        //   { required: true, message: '申请人不能为空', trigger: 'blur' }
        // ]
        // createTime: [
        //   { required: true, message: '创建时间不能为空', trigger: 'blur' }
        // ],
        // updateTime: [
        //   { required: true, message: '更新时间不能为空', trigger: 'blur' }
        // ]
      },
      queryTypeOptions: [
        { key: 'plant', display_name: '厂别/车间' },
        { key: 'plantName', display_name: '车间描述' },
        { key: 'docNo', display_name: '需求单号' },
        { key: 'callType', display_name: 'Auto自动 / Manual手动' },
        { key: 'callSystem', display_name: 'DCS叫料 / MES叫料' },
        { key: 'docType', display_name: '单据类型：Picking、Dispatch、OVER' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    checkDetail(item) {
      this.$router.push(`/dcsManagement/dcsOrderDetail?docNo=${item.docNo}`)
    }
  }
}
</script>

<style scoped>

</style>
